package com.redwolfsoft.libshoppingserver.brand;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


public class BrandShopArea {
	public final static String TAG = "BrandShopArea";
	
	public String id = null; //某个品牌所在地的id
	public String mDisplayName = null;//某个品牌所在地的名称
	public List<BrandShopInfo> mBrandShopInfoList = null;//专卖店列表（所有国家）
	
	public BrandShopArea(String id, String name, List<BrandShopInfo> list)
	{
		this.id=id;
		this.mDisplayName=name;
		mBrandShopInfoList = list;
	}
	
	public BrandShopArea(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
				
		id = obj.getString("id");
		mDisplayName = obj.getString("mDisplayName");			
		
		mBrandShopInfoList = new ArrayList<BrandShopInfo>();
		JSONArray array1 = obj.getJSONArray("mBrandShopInfoList");
		for(int i=0;i<array1.size();i++)
		{			
			JSONObject info = array1.getJSONObject(i);
			//Log.d(TAG,info.toString());
			mBrandShopInfoList.add(new BrandShopInfo(info));
		}
			
			
		
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		
		obj.put("id", id);
		obj.put("mDisplayName", mDisplayName);
		JSONArray array1 = new JSONArray();
		for(int i=0;i<mBrandShopInfoList.size();i++)
		{
			array1.add(i,mBrandShopInfoList.get(i).toJsonObject());
		}
		obj.put("mBrandShopInfoList", array1);
	
		return obj;
		
	}
}
